package demo2;

import java.util.Arrays;

public class Test {

    public static void bubbleSort(Comparable[] comparables){
        for(int i = 0; i < comparables.length - 1; i++){
            for (int j = 0; j < comparables.length - 1 - i; j++){
                if(comparables[j].compareTo(comparables[j+1]) > 0){
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan", 10, 89.3);
        students[1] = new Student("lisi", 5, 90.29);
        students[2] = new Student("abc", 15, 10.29);
        ScoreComparator scoreComparator = new ScoreComparator();
        // Arrays.sort(students, scoreComparator);

        // Arrays.sort(students);

        bubbleSort(students);

        System.out.println(Arrays.toString(students));
    }
    public static void main2(String[] args) {

        Person[] person = new Person[3];
        person[0] = new Person("zhangsan", 10, 90.3);
        person[1] = new Person("lisi", 5, 90.31);
        person[2] = new Person("abc", 15, 10.29);

        Arrays.sort(person);
        System.out.println(Arrays.toString(person));

        System.out.println("=====================");

        int[] array = {9,6,5,7,3};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main1(String[] args) {
        Student student1 = new Student("zhangsan", 20, 95.6);
        Student student2 = new Student("lisi", 19, 89.3);

        AgeComparator ageComparator = new AgeComparator();
        int ret = ageComparator.compare(student1, student2);
        if(ret > 0){
            System.out.println("年龄关系：student1 > student2");
        }

        ScoreComparator scoreComparator = new ScoreComparator();
        int ret2 = scoreComparator.compare(student1, student2);
        if(ret2 > 0){
            System.out.println("分数关系：student1 > student2");
        }else{
            System.out.println("分数关系：student1 < student2");
        }

        NameComparator nameComparator = new NameComparator();
        int ret3 = nameComparator.compare(student1, student2);
        if(ret3 > 0){
            System.out.println("姓名关系：student1 > student2");
        }else{
            System.out.println("姓名关系：student1 < student2");
        }

        ////////////////////Comparable接口////////////////////////////////////
        /*if(student1.compareTo(student2) > 0){
            System.out.println("student1 > student2");
        }*/

        /*int a = 10;
        int b = 20;
        if(a > b){
            System.out.println("a > b");
        }else{
            System.out.println("a < b");
        }*/
    }
}
